# write by 李大宝!
# in 2019,6,1

from flask import Flask, url_for, Response, jsonify, render_template
from werkzeug.routing import BaseConverter
import time
from datetime import datetime

app = Flask(__name__)


@app.template_filter('time_op')
def time_operate(time_value):
    if isinstance(time_value, datetime):
        endtime = datetime.now()
        seconds = (time_value-endtime).total_seconds()
        if seconds < 60:
            return '刚刚'
        if seconds < 60*60:
            return '%s分钟前' % int(seconds/60)
        if seconds < 60*60*24:
            return '%s小时前' % int(seconds/(60*60))
        else:
            return '%s天前' % int(seconds/(60*60*24))
    else:
        return "your time's template is not in great!"


@app.route('/')
def hello():
    return 'hello world'


@app.route('/login')
def login():
    return render_template('login.html', create_time=datetime(2017,))


if __name__ == '__main__':
    app.run(debug=True)
